Fix cargo doc with custom build commands
authorAlex Crichton <alex@alexcrichton.com>
Tue, 16 Sep 2014 14:47:39 +0000 (07:47 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 16 Sep 2014 19:09:42 +0000 (12:09 -0700)
There's no "doc-all" profile, so it needs to be canonicalized when finding the
name of the profile to pass to a build command.

src/cargo/ops/cargo_rustc/context.rs
src/cargo/ops/cargo_rustc/mod.rs
tests/test_cargo_doc.rs

index 2cb50d3976ccb110ff4ddb71d14fa4fc66c3b9d8..8307ed0cdcc356e18de5c34c4b4cd97736b6ae70 100644 (file)
@@ -22,8 +22,8 @@ pub struct Context<'a, 'b> {
     pub resolve: &'a Resolve,
     pub sources: &'a SourceMap<'b>,
     pub compilation: Compilation,
-    pub env: &'a str,
 
+    env: &'a str,
     host: Layout,
     target: Option<Layout>,
     target_triple: String,
@@ -268,6 +268,13 @@ impl<'a, 'b> Context<'a, 'b> {
             .expect("Should have found package")
     }
 
+    pub fn env(&self) -> &str {
+        // The "doc-all" environment just means to document everything (see
+        // below), but we want to canonicalize that the the "doc" profile
+        // environment, so do that here.
+        if self.env == "doc-all" {"doc"} else {self.env}
+    }
+
     pub fn is_relevant_target(&self, target: &Target) -> bool {
         target.is_lib() && match self.env {
             "doc" | "test" | "bench" => target.get_profile().is_compile(),
index ab155d31faf7ce4e9dbc439434afbfef35a69f6c..073110fdef35de08238d4790914c0ad1869dfd69 100644 (file)
@@ -172,11 +172,11 @@ fn compile_custom(pkg: &Package, cmd: &str,
                   cx: &Context, first: bool) -> CargoResult<Work> {
     let root = cx.get_package(cx.resolve.root());
     let profile = root.get_manifest().get_targets().iter()
-                      .find(|target| target.get_profile().get_env() == cx.env)
+                      .find(|target| target.get_profile().get_env() == cx.env())
                       .map(|target| target.get_profile());
     let profile = match profile {
         Some(profile) => profile,
-        None => return Err(internal(format!("no profile for {}", cx.env)))
+        None => return Err(internal(format!("no profile for {}", cx.env())))
     };
 
     // TODO: this needs to be smarter about splitting
index 71d33183905f8b89472a4741f97070ab671931ef..3f74f9282bab8b54c09b77cb21af29fda0328f0d 100644 (file)
@@ -12,6 +12,7 @@ test!(simple {
             name = "foo"
             version = "0.0.1"
             authors = []
+            build = 'true'
         "#)
         .file("src/lib.rs", r#"
             pub fn foo() {}